/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkUtil/MkSha1.h"
#include "MkUtil/MkUtil.h"
#include <gtest/gtest.h>

TEST(MkSha1, Sha1Test)
{
    MkString strTest = "abc";
    MkString strOut;
    Uint32 ErrorCode = MkSha1Encode(strTest, strOut);
    EXPECT_EQ(NoneError, ErrorCode);
    MkString StrStr;
    ErrorCode = CMkUtil::ByteToString((const Uint8*)strOut.c_str(), strOut.size(), StrStr);
    std::transform(StrStr.begin(),StrStr.end(),StrStr.begin(),::tolower);
    EXPECT_EQ(NoneError, ErrorCode);
    EXPECT_STREQ(StrStr.c_str(), "a9993e364706816aba3e25717850c26c9cd0d89d");
    StrStr.clear();
    strOut.clear();
    strTest = "123";
    ErrorCode = MkSha1Encode(strTest, strOut);
    EXPECT_EQ(NoneError, ErrorCode);
    ErrorCode = CMkUtil::ByteToString((const Uint8*)strOut.c_str(), strOut.size(), StrStr);
    std::transform(StrStr.begin(),StrStr.end(),StrStr.begin(),::tolower);
    EXPECT_EQ(NoneError, ErrorCode);
    EXPECT_STREQ(StrStr.c_str(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef");
}